package com.zeta.edw.venus

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

class ExtractIncrement extends ExtractData {

//  private def updateState(config: Config): Unit = {
//    val appConf = config.asInstanceOf[ExtractDataConfig]
//
//    // extract history data, no need to update state to zookeeper
//    if (appConf.checkStart.isDefined && appConf.checkEnd.isDefined) {
//      return
//    }
//
//    val zkClient = appConf.zkClient
//    val zkTablePath = appConf.zkTablePath
//
//    if (!zkClient.exists(zkTablePath)) {
//      zkClient.createPersistent(zkTablePath, true)
//    }

//    val jsonData = s"""{"last_value":"${appConf.defaultCheckEnd}","format":"${appConf.datetimeFormat}"}"""
//    logger.info(s"write to zookeeper: $jsonData")
//    zkClient.writeData(zkTablePath, jsonData)
//
//    zkClient.close()
//  }

  override def afterProcess(config: Config): Unit = {
   // updateState(config)
  }

  override def rangeStart(config: ExtractDataConfig): String = {
    val datetimeFormat = config.datetimeFormat

    LocalDateTime.now()
      .withHour(0).withMinute(0).withSecond(0).withNano(0)
      .minusDays(3).format(DateTimeFormatter.ofPattern(datetimeFormat))
  }

  override def rangeEnd(config: ExtractDataConfig): String = {
    val datetimeFormat = config.datetimeFormat

    LocalDateTime.now()
      .withHour(0).withMinute(0).withSecond(0).withNano(0)
      .plusDays(1).format(DateTimeFormatter.ofPattern(datetimeFormat))
  }
}

object ExtractIncrement extends ExtractIncrement {
  def main(args: Array[String]): Unit = {
    startApp(args, new ExtractDataConfig())
  }
}